﻿// 5. You are given an array of strings. Write a method that sorts the array by the length of its elements
// (the number of characters composing them).

using System;

class SortArrayByStringLength
{
    static void Main()
    {
        // get the array's dimension
        Console.Write("Enter the dimension of the array : ");
        string sizeStr = Console.ReadLine();
        int size;
        while (!int.TryParse(sizeStr, out size))
        {
            Console.Write("Invalid input. Enter again the array's dimension : ");
            sizeStr = Console.ReadLine();
        }

        // define the array
        string[] array = new string[size];
        // enter values for the cells
        Console.WriteLine("Enter the cells of the array:");
        for (int num = 0; num < size; num++)
        {
            Console.Write("array[{0}] = ", num);
            array[num] = Console.ReadLine();
        }

        // sort the array with lambda expression
        Array.Sort(array, (string1, string2) => (string1.Length).CompareTo(string2.Length));
        foreach (string element in array)
        {
            Console.WriteLine(element);
        }
    }
}